@import "mixin.scss";
@import "asset/responsive";
@import "asset/helper";
@import "asset/pseudo-class";
@import "asset/container";
@import "asset/flex-layout";
@import "asset/grid-layout";

@import "asset/preflight";
$namespace: if($namespace =="", "", "#{$namespace}-");
//$use-important
//$use-important-on-display
//$custom-properties
$pseudo-class-disabled: map-get($pseudo-class, "disabled");
$pseudo-class-suffix: map-get($pseudo-class, "suffix");
$pseudo-class-list: map-get($pseudo-class, "list");

$responsive-disabled: map-get($responsive, "disabled");
$responsive-suffix: map-get($responsive, "suffix");
$responsive-type: map-get($responsive, "type");
$responsive-breakpoints: map-get($responsive, "breakpoints");

@if length($custom-properties)!= 0 {
    :root {
        @each $c, $v in $custom-properties {
            --#{$c}: #{$v};
        }
    }
}

@if not map-get($container, "disabled") {
    $container-centered: map-get($container, "centered");
    $container-padding: map-get($container, "padding");
    @include build-container($container-centered, $container-padding);
}

$flex-layout: map-get($layout, "flex");
@if not map-get($flex-layout,"disabled") {
    $flex-layout-column: map-get($flex-layout, "column");
    $flex-layout-gap: map-get($flex-layout, "gap");
    @include build-flex-layout($flex-layout-column, $flex-layout-gap);
}

$grid-layout: map-get($layout, "grid");
@if not map-get($grid-layout,"disabled") {
    $grid-layout-column: map-get($grid-layout, "column");
    $grid-layout-row: map-get($grid-layout, "row");
    $grid-layout-gap: map-get($grid-layout, "gap");
    @include build-grid-layout($grid-layout-column, $grid-layout-row, $grid-layout-gap);
}

@each $key, $val in $ultimate {
    @if map-get($val,"disabled") != true {

        $responsive: map-get($val, "responsive");
        $pseudo-class: map-get($val, "pseudo-class");
        $property: map-get($val, "property");
        $class: map-get($val, "class");
        $values: map-get($val, "values");
        $mixin: map-get($val, "mixin");
        

        @if $mixin == null {
            @if type-of($values) != "map" {
                @error "Values must be a map in: #{$key}";
            }

            @if $class == null {
                $class: $property;
            }
            
            @if $responsive == null {
                $responsive: false;   
            }

            $pseudo-class-enabled: false;
            @if type-of($pseudo-class) == "list" and length($pseudo-class) != 0 {
                $pseudo-class-enabled: true;
            }

            @if $responsive and $pseudo-class-enabled {
                @include build-responsive() using($responsive-name,$responsive-width) {
                    @include build-pseudo-class($pseudo-class) using($pseudo-class-name,$pseudo-class-selector) {
                        @include build-class($class, $values, $property, $responsive-name, $pseudo-class-name, $pseudo-class-selector);
                    }
                }
            } @else if not $responsive and $pseudo-class-enabled {
                @include build-pseudo-class($pseudo-class) using($pseudo-class-name,$pseudo-class-selector) {
                    @include build-class($class, $values, $property, null, $pseudo-class-name, $pseudo-class-selector);
                }
            } @else if $responsive and not $pseudo-class-enabled {
                @include build-responsive() using($responsive-name,$responsive-width) {
                    @include build-class($class, $values, $property, $responsive-name);
                }
            } @else {
                @include build-class($class, $values, $property);
            }

        } @else {
            @each $m in $mixin {
                @include acorn-mixin($m);
            }
        }
    }
}